package main

import (
	"fmt"
	"os"

	"github.com/gin-gonic/gin"
)

type UserInfo struct {
	Name string  `form:"name"`
	Age  int     `form:"age"`
	Sex  string  `form:"sex"`
	File os.File `form:"upload"`
}

func main() {
	router := gin.Default()
	router.POST("/form", func(c *gin.Context) {
		var userInfo UserInfo
		fmt.Println("raw data:")
		raw, _ := c.GetRawData()
		fmt.Println(string(raw))
		err := c.ShouldBind(&userInfo)
		if err != nil {
			fmt.Println(err)
			c.JSON(200, gin.H{"msg": "你错了"})
			return
		}
		c.JSON(200, userInfo)
	})

	router.Run(":8000")
}
